package com.aspose.cells;

import java.io.InputStream;
import java.util.ArrayList;

public class CellsHelper {
   private static String a = null;
   private static String b = null;
   private static String c = null;
   private static String d;

   public static String getVersion() {
      return com.aspose.cells.a.c.zs.a();
   }

   /** @deprecated */
   public static boolean isProtectedByRMS(String fileName) throws Exception {
      return FileFormatUtil.detectFileFormat(fileName).c;
   }

   /** @deprecated */
   public static boolean isProtectedByRMS(InputStream stream) throws Exception {
      new com.aspose.cells.b.a.d.zi(stream);
      return FileFormatUtil.detectFileFormat(stream).c;
   }

   public static int[] cellNameToIndex(String cellName) {
      boolean var1 = false;
      boolean var2 = false;
      if (cellName == null) {
         throw new CellsException(6, "Invalid cell name");
      } else {
         int var6 = 0;
         boolean var3 = false;

         int var7;
         for(var7 = 0; var7 < cellName.length(); ++var7) {
            int var4 = cellName.charAt(var7) | 32;
            if (var4 < 97 || var4 > 122) {
               break;
            }

            var6 = var6 * 26 + var4 - 97 + 1;
         }

         if (var7 != 0 && var7 != cellName.length()) {
            --var6;

            int var5;
            for(var5 = 0; var7 < cellName.length(); ++var7) {
               char var8 = cellName.charAt(var7);
               if (var8 < '0' || var8 > '9') {
                  break;
               }

               var5 = var5 * 10 + cellName.charAt(var7) - 48;
            }

            if (var7 == cellName.length() && var5 != 0) {
               --var5;
               if (var5 <= 1048575 && var6 <= 16383) {
                  return new int[]{var5, var6};
               } else {
                  throw new CellsException(6, "Invalid cell name");
               }
            } else {
               throw new CellsException(6, "Invalid cell name");
            }
         } else {
            throw new CellsException(6, "Invalid cell name");
         }
      }
   }

   static void a(String var0, int[] var1, int[] var2) {
      if (var0 == null) {
         throw new CellsException(6, "Invalid cell name");
      } else {
         var2[0] = 0;
         boolean var3 = false;

         int var5;
         for(var5 = 0; var5 < var0.length(); ++var5) {
            int var4 = var0.charAt(var5) | 32;
            if (var4 < 97 || var4 > 122) {
               break;
            }

            var2[0] = var2[0] * 26 + var4 - 97 + 1;
         }

         if (var5 != 0 && var5 != var0.length()) {
            --var2[0];

            for(var1[0] = 0; var5 < var0.length(); ++var5) {
               char var6 = var0.charAt(var5);
               if (var6 < '0' || var6 > '9') {
                  break;
               }

               var1[0] = var1[0] * 10 + var0.charAt(var5) - 48;
            }

            if (var5 == var0.length() && var1[0] != 0) {
               --var1[0];
               if (var1[0] > 1048575 || var2[0] > 16383) {
                  throw new CellsException(6, "Invalid cell name");
               }
            } else {
               throw new CellsException(6, "Invalid cell name");
            }
         } else {
            throw new CellsException(6, "Invalid cell name");
         }
      }
   }

   static int[] a(char[] var0, int var1, int var2, boolean var3, int var4, int var5) {
      int var6 = -1;
      int var7 = -1;
      byte var8 = 0;
      byte var9 = 0;

      for(int var10 = var1; var10 <= var2; ++var10) {
         switch(var0[var10]) {
         case '$':
            break;
         case '%':
         case '&':
         case '\'':
         case '(':
         case ')':
         case '*':
         case '+':
         case ',':
         case '-':
         case '.':
         case '/':
         case '0':
         case ':':
         case ';':
         case '<':
         case '=':
         case '>':
         case '?':
         case '@':
         case '[':
         case '\\':
         case ']':
         case '^':
         case '_':
         case '`':
         default:
            return null;
         case '1':
         case '2':
         case '3':
         case '4':
         case '5':
         case '6':
         case '7':
         case '8':
         case '9':
            if (var6 != -1) {
               return null;
            }

            if (var10 != var1 && var0[var10 - 1] == '$') {
               var9 = 1;
            }

            var6 = var0[var10] - 48;
            ++var10;

            while(var10 <= var2) {
               if (!Character.isDigit(var0[var10])) {
                  return null;
               }

               var6 = var6 * 10 + var0[var10] - 48;
               ++var10;
            }

            --var6;
            if (var6 > var4) {
               return null;
            }
            break;
         case 'A':
         case 'B':
         case 'C':
         case 'D':
         case 'E':
         case 'F':
         case 'G':
         case 'H':
         case 'I':
         case 'J':
         case 'K':
         case 'L':
         case 'M':
         case 'N':
         case 'O':
         case 'P':
         case 'Q':
         case 'R':
         case 'S':
         case 'T':
         case 'U':
         case 'V':
         case 'W':
         case 'X':
         case 'Y':
         case 'Z':
         case 'a':
         case 'b':
         case 'c':
         case 'd':
         case 'e':
         case 'f':
         case 'g':
         case 'h':
         case 'i':
         case 'j':
         case 'k':
         case 'l':
         case 'm':
         case 'n':
         case 'o':
         case 'p':
         case 'q':
         case 'r':
         case 's':
         case 't':
         case 'u':
         case 'v':
         case 'w':
         case 'x':
         case 'y':
         case 'z':
            if (var7 != -1 || var6 != -1) {
               return null;
            }

            int var11;
            for(var11 = var10 + 1; var11 <= var2 && Character.isLetter(var0[var11]); ++var11) {
               ;
            }

            if (var10 != var1 && var0[var10 - 1] == '$') {
               var8 = 1;
            }

            var7 = (var0[var10] | 32) - 97 + 1;
            ++var10;

            while(var10 < var11) {
               var7 = var7 * 26 + (var0[var10] | 32) - 97 + 1;
               ++var10;
            }

            --var10;
            --var7;
            if (var7 > var5) {
               return null;
            }
         }
      }

      if (var6 == -1 && var7 == -1) {
         return null;
      } else if (var3 || var6 != -1 && var7 != -1) {
         int[] var12 = new int[]{var6, var7, var9, var8};
         return var12;
      } else {
         return null;
      }
   }

   public static String cellIndexToName(int row, int column) {
      zakq.a(row, column);
      ++row;
      return columnIndexToName(column) + com.aspose.cells.b.a.zo.a(row);
   }

   public static String columnIndexToName(int column) {
      if (column >= 0 && column <= 16383) {
         String var1 = Character.toString((char)(column % 26 + 65));
         if (column < 26) {
            return var1;
         } else {
            column /= 26;

            int var3;
            for(boolean var2 = false; column > 0; var1 = Character.toString((char)(var3 + 65)) + var1) {
               var3 = (column - 1) % 26;
               column = (column - 1) / 26;
            }

            return var1;
         }
      } else {
         throw new IllegalArgumentException();
      }
   }

   public static int columnNameToIndex(String columnName) {
      int var1 = 0;

      for(int var2 = 0; var2 < columnName.length(); ++var2) {
         if (!Character.isLetter(columnName.charAt(var2))) {
            throw new CellsException(6, "Invalid Column name.");
         }

         var1 = var1 * 26 + (columnName.charAt(var2) | 32) - 97 + 1;
      }

      if (var1 > 0) {
         --var1;
      }

      if (var1 > 16383) {
         throw new CellsException(10, "Invalid Column name.");
      } else {
         return var1;
      }
   }

   public static String rowIndexToName(int row) {
      ++row;
      return com.aspose.cells.b.a.zo.a(row);
   }

   public static int rowNameToIndex(String rowName) {
      int var1 = com.aspose.cells.b.a.zo.a(rowName);
      --var1;
      return var1;
   }

   public static String convertR1C1FormulaToA1(String r1c1Formula, int row, int column) {
      return zasp.b(r1c1Formula, row, column);
   }

   public static String convertA1FormulaToR1C1(String formula, int row, int column) {
      return zasp.a(formula, row, column);
   }

   public static DateTime getDateTimeFromDouble(double doubleValue, boolean date1904) {
      return zbtq.a(doubleValue, date1904);
   }

   public static double getDoubleFromDateTime(DateTime dateTime, boolean date1904) {
      return zbtq.a(dateTime, date1904);
   }

   /** @deprecated */
   public static int detectLoadFormat(String fileName) throws Exception {
      return FileFormatUtil.detectFileFormat(fileName).getLoadFormat();
   }

   /** @deprecated */
   public static int detectLoadFormat(InputStream stream) throws Exception {
      return FileFormatUtil.detectFileFormat(stream).getLoadFormat();
   }

   /** @deprecated */
   public static int detectFileFormat(String fileName) throws Exception {
      return FileFormatUtil.detectFileFormat(fileName).getFileFormatType();
   }

   /** @deprecated */
   public static int detectFileFormat(InputStream stream) throws Exception {
      return FileFormatUtil.detectFileFormat(stream).getFileFormatType();
   }

   public static String getFontDir() {
      return com.aspose.cells.a.d.zfs.a();
   }

   public static void setFontDir(String value) {
      com.aspose.cells.a.d.zfs.a(value);
      new com.aspose.cells.a.d.zfs(true);
   }

   public static ArrayList getFontDirs() {
      return com.aspose.cells.a.d.zfs.a;
   }

   public static void setFontDirs(ArrayList value) {
      com.aspose.cells.a.d.zfs.a = value;
      new com.aspose.cells.a.d.zfs(true);
   }

   public static ArrayList getFontFiles() {
      return com.aspose.cells.a.d.zfs.b;
   }

   public static void setFontFiles(ArrayList value) {
      com.aspose.cells.a.d.zfs.b = value;
      new com.aspose.cells.a.d.zfs(true);
   }

   public static String getStartupPath() {
      return a;
   }

   public static void setStartupPath(String value) {
      a = value;
   }

   public static String getAltStartPath() {
      return b;
   }

   public static void setAltStartPath(String value) {
      b = value;
   }

   public static String getLibraryPath() {
      return c;
   }

   public static void setLibraryPath(String value) {
      c = value;
   }

   public static Color[] getUsedColors(Workbook workbook) {
      return zasu.a(workbook);
   }

   public static void addAddInFunction(String function, int minCountOfParameters, int maxCountOfParameters, int[] paramersType, int fuctionValueType) {
      int[] var5 = new int[paramersType.length];

      for(int var6 = 0; var6 < var5.length; ++var6) {
         switch(paramersType[var6]) {
         case 0:
            var5[var6] = 32;
            break;
         case 1:
            var5[var6] = 64;
            break;
         case 2:
            var5[var6] = 96;
         }
      }

      byte var7 = 64;
      switch(fuctionValueType) {
      case 0:
         var7 = 32;
         break;
      case 2:
         var7 = 96;
      }

      zabl.a(function, minCountOfParameters, maxCountOfParameters, var5, var7);
   }

   public static void mergeFiles(String[] files, String cachedFile, String destFile) throws Exception {
      zanj var3 = new zanj();
      var3.a(files, cachedFile, destFile);
   }

   static void a(String var0) {
      d = var0;
      com.aspose.cells.a.d.zei.e(var0);
   }
}
